package com.tianyang.yukuaifu.module.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;

import androidx.core.content.ContextCompat;

import com.tianyang.yukuaifu.R;
import com.tianyang.yukuaifu.module.dialog.interfaces.MerchantFilterListener;
import com.tianyang.yukuaifu.module.roundview.RoundTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：商户列表筛选
 * Created by xyj on 2024/11/14
 */
public class MerchantFilterDialog extends Dialog {

    @BindView(R.id.mchType1Rtv)
    RoundTextView mchType1Rtv;
    @BindView(R.id.mchType2Rtv)
    RoundTextView mchType2Rtv;
    @BindView(R.id.mchType3Rtv)
    RoundTextView mchType3Rtv;
    @BindView(R.id.authStatus1Rtv)
    RoundTextView authStatus1Rtv;
    @BindView(R.id.authStatus2Rtv)
    RoundTextView authStatus2Rtv;

    private Context mContext;

    private MerchantFilterListener listener;

    private int mchTypeFilter = -1, authStatusFilter = -1;

    public void setListener(MerchantFilterListener listener) {
        this.listener = listener;
    }

    public MerchantFilterDialog(Context context) {
        super(context, R.style.top_pop_menu);
        this.mContext = context;
        setContentView(R.layout.dialog_merchant_filter);
        ButterKnife.bind(this);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    @OnClick({R.id.mchType1Rtv, R.id.mchType2Rtv, R.id.mchType3Rtv, R.id.authStatus1Rtv, R.id.authStatus2Rtv,
            R.id.resetRtv, R.id.confirmRtv, R.id.emptyView})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.confirmRtv:
                if(listener != null) {
                    listener.callback(mchTypeFilter, authStatusFilter);
                }
                dismiss();
                break;
            case R.id.resetRtv:
                showMchTypeView(-1);
                showAuthStatusView(-1);
                break;
            case R.id.mchType1Rtv:
                showMchTypeView(1);
                break;
            case R.id.mchType2Rtv:
                showMchTypeView(0);
                break;
            case R.id.mchType3Rtv:
                showMchTypeView(2);
                break;
            case R.id.authStatus1Rtv:
                showAuthStatusView(1);
                break;
            case R.id.authStatus2Rtv:
                showAuthStatusView(0);
                break;
            case R.id.emptyView:
                dismiss();
                break;
        }
    }

    private void showMchTypeView(int mchType) {
        mchTypeFilter = mchType;
        mchType1Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.transparent));
        mchType2Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.transparent));
        mchType3Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.transparent));
        switch (mchType) {
            case 0:
                mchType1Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.c_333333));
                break;
            case 1:
                mchType2Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.c_333333));
                break;
            case 2:
                mchType3Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.c_333333));
                break;
        }
    }

    private void showAuthStatusView(int authStatus) {
        authStatusFilter = authStatus;
        authStatus1Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.transparent));
        authStatus2Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.transparent));
        switch (authStatus) {
            case 0:
                authStatus1Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.c_333333));
                break;
            case 1:
                authStatus2Rtv.getDelegate().setStrokeColor(ContextCompat.getColor(mContext, R.color.c_333333));
                break;
        }
    }
}
